package com.hdax.dm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hdax.dm.beans.item.Item;
import com.hdax.dm.beans.item.cinema;
import com.hdax.dm.dto.seniorityDto;
import com.hdax.dm.mappers.seniorityMapper;
import com.hdax.dm.mapstucts.seniorityDtoMapper;
import com.hdax.dm.service.seniorityService;
import com.hdax.dm.utils.response.CommonResponse;
import com.hdax.dm.utils.response.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class seniorityServiceImpl extends ServiceImpl<seniorityMapper, Item> implements seniorityService {

    @Autowired
    private seniorityDtoMapper seniorityDtoMapper;

    @Autowired
    private cinemaServiceImpl cinemaService;

    @Override
    public CommonResponse<List<seniorityDto>> seniority(Map<String,Long> itemTypeId) {
        Long id = itemTypeId.get("itemTypeId");
        QueryWrapper<Item> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("isRecommend",1L);
        queryWrapper.eq("itemType1Id",id);
        queryWrapper.last("limit 11");
        List<Item> lists = baseMapper.selectList(queryWrapper);

        Integer cinemaId = null;
        for (Item o:lists) {
            cinemaId=o.getCinemaId().intValue();
        }

        List<seniorityDto> dtos = seniorityDtoMapper.toTargetList(lists);

        for (seniorityDto dto : dtos) {
            cinema c = cinemaService.selectOne(cinemaId);
            dto.setAreaId(c.getAreaId());
            dto.setAreaName(c.getAreaName());
        }
        return ResponseUtil.returnSuccess(dtos);
    }
}
